<?php

namespace App;

use Encore\Admin\Traits\DefaultDatetimeFormat;
use Illuminate\Database\Eloquent\Model;

class Expert extends Model
{
    use DefaultDatetimeFormat;

    protected $table = 'admin_users';

    protected $fillable = ['username', 'password', 'name', 'mobile', 'company', 'bank', 'bank_account', 'role_type', 'major', 'enabled', 'academic_title'];


    public static function selectAllOptions(): array
    {
        return self::query()->where('role_type', 3)->pluck('name', 'id')->toArray();
    }

    public static function expertSelectOptions(): array
    {
        return self::query()->where('role_type', 3)
            ->where('enabled', 1)
            ->get()
            ->map(function ($item) {
                $item['name'] = sprintf('(%s)%s---%s', $item['company'], $item['name'], $item['major']);
                return $item;
            })->pluck('name', 'id')->toArray();
    }

    public static function expertSelectAllOptions(): array
    {
        return self::query()->where('role_type', 3)
            ->get()
            ->map(function ($item) {
                $item['name'] = sprintf('(%s)%s---%s', $item['company'], $item['name'], $item['major']);
                return $item;
            })->pluck('name', 'id')->toArray();
    }

    public function agency(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Agency::class);
    }

}
